package com.uex.dev.manage.admin.config;

import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.uex.dev.manage.admin.po.UserPO;
import com.uex.dev.manage.admin.vo.wx.OpenidInfo;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @author lzs
 * @create 2024/02/22
 * @description
 */
@Data
@ConfigurationProperties(prefix = "robot.admin")
@Component
public class AdminConfig {
    private String passwdSalt;
    private Integer loginTimeout;
    private Integer thirdTokenTimeout;
    private String defaultPwd;

    @Bean(name = "tokenCache")
    public LoadingCache<String, UserPO> getTokenCache() {
        LoadingCache<String, UserPO> cache = CacheBuilder.newBuilder()
                .expireAfterWrite(loginTimeout, TimeUnit.SECONDS)
                .build(new CacheLoader<>() {
                    @Override
                    public UserPO load(String key) {
                        return null;
                    }
                });
        return cache;
    }

    @Bean(name = "openIdCache")
    public LoadingCache<String, OpenidInfo> getOpenIdCache() {
        LoadingCache<String, OpenidInfo> cache = CacheBuilder.newBuilder()
                .expireAfterWrite(loginTimeout, TimeUnit.SECONDS)
                .build(new CacheLoader<>() {
                    @Override
                    public OpenidInfo load(String key) {
                        return null;
                    }
                });
        return cache;
    }
}

